from sqlalchemy import Column, String, Text, Enum, ForeignKey
from sqlalchemy.dialects.postgresql import UUID
from sqlalchemy.orm import relationship
import uuid

from db.base import Base

class IssueSeverity(str, Enum):
    HIGH = 'high'
    MEDIUM = 'medium'
    LOW = 'low'

class IssueType(str, Enum):
    TYPO = 'typo'
    SEMANTIC = 'semantic'
    RISK_LEVEL = 'risk-level'
    COMPLIANCE_STATUS = 'compliance-status'

class ComplianceItemIssue(Base):
    """Database model for compliance item issues."""
    __tablename__ = "compliance_item_issue"

    id = Column(UUID(as_uuid=True), primary_key=True, default=uuid.uuid4, index=True)
    item_id = Column(UUID(as_uuid=True), ForeignKey("compliance_item.id"), nullable=False, index=True)
    plan_id = Column(UUID(as_uuid=True), ForeignKey("assessment_plan.id"), nullable=False, index=True)
    type = Column(String(255), nullable=False)
    severity = Column(String(255), nullable=False)
    title = Column(String(255), nullable=False)
    description = Column(Text, nullable=False)
    suggestion = Column(Text, nullable=False)
    original_content = Column(Text, nullable=True)
    original_description = Column(Text, nullable=True)

    # Relationships
    compliance_item = relationship("ComplianceItem", back_populates="issues")
    assessment_plan = relationship("AssessmentPlan", back_populates="issues")
